package postpic.domain;

import java.util.Date;

import org.json.JSONObject;

import postpic.json.JSONSerializable;

public class Comment implements JSONSerializable {
	
	private Integer commentId;
	private Integer userId;
	private String userName;
	private Integer photoId;
	private Date commentDate;
	private String commentText;
	
	public Comment() {
		
	}
	
	public Comment(JSONObject json) {
		populateFromJSON(json);
	}

	public Integer getCommentId() {
		return commentId;
	}

	public void setCommentId(Integer commentId) {
		this.commentId = commentId;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	
	public String getUserName()
	{
		return userName;
	}
	
	public void setUserName(String userName)
	{
		this.userName = userName;
	}

	public Integer getPhotoId() {
		return photoId;
	}

	public void setPhotoId(Integer photoId) {
		this.photoId = photoId;
	}

	public Date getCommentDate() {
		return commentDate;
	}

	public void setCommentDate(Date commentDate) {
		this.commentDate = commentDate;
	}

	public String getCommentText() {
		return commentText;
	}

	public void setCommentText(String commentText) {
		this.commentText = commentText;
	}

	@Override
	public JSONObject getJSON() {
		JSONObject json = new JSONObject();
		json.put("commentId", commentId);
		json.put("userId", userId);
		json.put("userName", userName);
		json.put("photoId", photoId);
		json.put("commentDate", commentDate.getTime());
		json.put("commentText", commentText);
		return json;
	}

	@Override
	public void populateFromJSON(JSONObject json) {
		setCommentId(json.getInt("commentId"));
		setUserId(json.getInt("userId"));
		setUserName(json.getString("userName"));
		setPhotoId(json.getInt("photoId"));
		setCommentDate(new Date(json.getLong("commentDate")));
		setCommentText(json.getString("commentText"));
	}
	
	@Override
	public String toString(){
		return getJSON().toString();
	}
	
	
	
	

}
